package com.woniu40.petai_user.web;

import com.woniu40.petai_user.entity.Comment;
import com.woniu40.petai_user.entity.User;
import com.woniu40.petai_user.service.CommentService;

import com.woniu40.petai_user.service.UserService;
import com.woniu40.petai_user.vo.UserVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpSession;
import java.util.Date;
import java.util.Map;

@Controller
public class CommentController {

    @Autowired
    CommentService commentService ;

    @Autowired
    UserService userService;

    @RequestMapping("/addComment")
    public String addComment(Comment comment, Map map, HttpSession session){
        System.out.println("==================================================");
        Integer dynamicId = comment.getDynamicId();
        comment.setParentId(-1);
        User user = (User) session.getAttribute("user");
        Integer userId = user.getUserId();
        comment.setUserId(userId);
        Date createTime = new Date();
        comment.setCreateTime(createTime);
        int i = commentService.addComment(comment);
        if (i!=0){
            map.put("result","添加成功");
        }else {
            map.put("result","添加失败");
        }

        return "redirect:dynamic/queryDynamic?DynamicId="+dynamicId;
    }


}
